#ifndef __QE_METRIC_H__
#define __QE_METRIC_H__

#include "qe_def.h"
#include "qe_time.h"

typedef struct
{
    double val;
    double min;
    double max;
} qe_metric_dv;

typedef struct
{
    qe_u64 bytes;
    qe_u32 period_sec;
    qe_time_t pts;
    qe_metric_dv bps;
} qe_metric_bps;

/**
 * Packet loss rate
 */
typedef struct
{
    qe_uint count;
    qe_uint losscnt;
    qe_uint lossval;
    qe_int max;
    qe_u32 period_sec;
    qe_time_t pts;
    qe_metric_dv rate;
} qe_metric_per;

typedef struct
{
    qe_time_t pts;
    qe_metric_dv delay;
} qe_metric_delay;

typedef struct
{
    qe_u32 pkts;
    qe_time_t pts;
    qe_u32 period_sec;
    qe_metric_dv pps;
} qe_metric_pps;

qe_const_str qe_bps_str(double bps);

void 
qe_metric_bps_init(qe_metric_bps *metric, qe_u32 period_sec);

qe_bool 
qe_metric_bps_update(qe_metric_bps *metric, qe_u64 bytes);

void 
qe_metric_bps_clean(qe_metric_bps *metric);

double 
qe_metric_bps_get(qe_metric_bps *metric);

double 
qe_metric_bps_get_min(qe_metric_bps *metric);

double 
qe_metric_bps_get_max(qe_metric_bps *metric);

qe_const_str 
qe_metric_bps_get_str(qe_metric_bps *metric);

qe_const_str 
qe_metric_bps_get_min_str(qe_metric_bps *metric);

qe_const_str 
qe_metric_bps_get_max_str(qe_metric_bps *metric);

void 
qe_metric_per_init(qe_metric_per *metric, qe_u32 period_sec, qe_int max);

qe_bool 
qe_metric_per_update(qe_metric_per *metric, qe_uint count);

void 
qe_metric_per_clean(qe_metric_per *metric);

qe_uint 
qe_metric_per_get_count(qe_metric_per *metric);

double 
qe_metric_per_get(qe_metric_per *metric);

double 
qe_metric_per_get_min(qe_metric_per *metric);

double 
qe_metric_per_get_max(qe_metric_per *metric);

qe_const_str 
qe_metric_per_get_str(qe_metric_per *metric);

qe_const_str 
qe_metric_per_get_min_str(qe_metric_per *metric);

qe_const_str 
qe_metric_per_get_max_str(qe_metric_per *metric);

void 
qe_metric_delay_init(qe_metric_delay *metric);

void 
qe_metric_delay_clean(qe_metric_delay *metric);

void 
qe_metric_delay_start(qe_metric_delay *metric);

void 
qe_metric_delay_stop(qe_metric_delay *metric);

double 
qe_metric_delay_get(qe_metric_delay *metric);

qe_const_str 
qe_metric_delay_get_str(qe_metric_delay *metric);

qe_const_str 
qe_metric_delay_get_min_str(qe_metric_delay *metric);

qe_const_str 
qe_metric_delay_get_max_str(qe_metric_delay *metric);

void
qe_metric_pps_init(qe_metric_pps *pps, qe_u32 period_sec);

void
qe_metric_pps_update(qe_metric_pps *pps, qe_u32 num);

void 
qe_metric_pps_clean(qe_metric_pps *pps);

qe_const_str 
qe_metric_pps_get_str(qe_metric_pps *pps);

qe_const_str 
qe_metric_pps_get_str_min(qe_metric_pps *pps);

qe_const_str 
qe_metric_pps_get_str_max(qe_metric_pps *pps);

#endif /* __QE_METRIC_H__ */